﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UofCASE.AgileProductLinerDSL;
using UofCASE.GreenPepe.Extensibility;

namespace APLDTests {
    [TestClass]
    public class GreenPepeConnectorTest {
        
        [TestMethod]
        public void TestGetAllUmarkedTests() {
            ModelHelper model = ModelHelper.GetModel(true);
            TestShape testShape = model.GetElement<TestShape>("testShape");
            GreenPepeConnector connector = new GreenPepeConnector(new MockGreenPepeService(6));
            TestInformation testInfo = connector.GetAllUnmappedTests(model.Store).ElementAt(0);
            IList<TestInformation> testInfos = connector.GetAllUnmappedTests(model.Store);
            Assert.AreEqual(6, testInfos.Count);
            CommandHandler.MapTest(testShape, testInfo.RelativePath, testInfo.ProjectUniqueName);
            testInfos = connector.GetAllUnmappedTests(model.Store);
            Assert.AreEqual(5, testInfos.Count);
            Assert.AreEqual(@"Project\Tests\Test2.html", testInfos.ElementAt(0).RelativePath);
        }

        [TestMethod]
        public void TestGetAllMarkedTests() {
            ModelHelper model = ModelHelper.GetModel(true);
            TestShape testShape = model.GetElement<TestShape>("testShape");
            GreenPepeConnector connector = new GreenPepeConnector(new MockGreenPepeService(6));
            TestInformation testInfo = connector.GetAllUnmappedTests(model.Store).ElementAt(0);
            IList<TestInformation> testInfos = connector.GetAllMappedTests(model.Store);
            Assert.AreEqual(0, testInfos.Count);
            CommandHandler.MapTest(testShape, testInfo.RelativePath, testInfo.ProjectUniqueName);
            testInfos = connector.GetAllMappedTests(model.Store);
            Assert.AreEqual(1, testInfos.Count);
            Assert.AreEqual(@"Project\Tests\Test1.html", testInfos.ElementAt(0).RelativePath);
        }

        [TestMethod]
        public void TestGetAllTests() {
            ModelHelper model = ModelHelper.GetModel(true);
            TestShape testShape = model.GetElement<TestShape>("testShape");
            GreenPepeConnector connector = new GreenPepeConnector(new MockGreenPepeService(6));
            TestInformation testInfo = connector.GetAllUnmappedTests(model.Store).ElementAt(0);
            IList<TestInformation> testInfos = connector.GetAllTests(model.Store);
            Assert.AreEqual(6, testInfos.Count);
            CommandHandler.MapTest(testShape, testInfo.RelativePath, testInfo.ProjectUniqueName);
            testInfos = connector.GetAllTests(model.Store);
            Assert.AreEqual(6, testInfos.Count);
            Assert.AreEqual(@"Project\Tests\Test1.html", testInfos.ElementAt(0).RelativePath);
        }
    }
}
